package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.BuildingManagement;
import com.example.mybatisplus.model.domain.Student;
import com.example.mybatisplus.mapper.StudentMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.vo.StatVO;
import com.example.mybatisplus.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ablbb
 * @since 2024-07-22
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public Page<Student> pageList(Student student, PageDTO dto){
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(student.getCommunityId())){
            wrapper.like("community_id",student.getCommunityId());
        }
        if (student.getFloor() != null) {
            int floor = student.getFloor();
            wrapper.like("floor", floor);  // 使用整数进行条件操作
        }
        if (StringUtils.isNotBlank(student.getBuildingId())){
            wrapper.like("building_id",student.getBuildingId());
        }
        if (student.getRoomId() != null) {
            int room = student.getRoomId();
            wrapper.like("room_id", room);  // 使用整数进行条件操作
        }
        if (student.getBedId() != null) {
            int bed = student.getBedId();
            wrapper.like("bed_id", bed);  // 使用整数进行条件操作
        }
        if (student.getPrice() != null) {
            int price = student.getPrice();
            wrapper.like("price", price);  // 使用整数进行条件操作
        }
        if (student.getIsLived() != null) {
            wrapper.eq("is_lived", student.getIsLived()); // 使用 eq() 进行精确匹配
        }
        if (StringUtils.isNotBlank(student.getStudentRole())) {
            wrapper.eq("student_role", student.getStudentRole());
        }
        Page<Student> page =new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPageSize());
        baseMapper.selectPage(page,wrapper);
        return page;

    }

    @Override
    public List<StatVO> stat() {
        return baseMapper.stat();
    }

    @Override
    public List<StatVO> statmajor() {
        return baseMapper.statmajor();
    }

    @Override
    public List<StatVO> statedu() {
        return baseMapper.statedu();
    }

   /* public Page<Student> getStudentsByRole(String studentRole, int pageNo, int pageSize) {
        Page<Student> page = new Page<>(pageNo, pageSize);
        return baseMapper.getStudentsByRole(page, studentRole);
    }*/
}
